package com.itheima.tliaswebmanagement.handle;

import com.itheima.tliaswebmanagement.exception.BaseException;
import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.sun.net.httpserver.Authenticator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description GlobalExceptionHandle
 * @Author ziguan ling
 * @Date 2025--01--09
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        e.printStackTrace();

        log.info("1.发生异常:" + e.getMessage());
        log.info("2.记录日志");
        log.info("3.通知管理员...");
        log.info("4.返回异常信息到客户端");
        return Result.error("sorry,你的网络可能存在问题,请检查后重试");
    }
    @ExceptionHandler(BaseException.class)
    public Result namesAreIrregularException(BaseException e) {
        log.info("1.发生异常:" + e.getMessage());
        log.info("2.记录日志");
        log.info("3.放回异常信息到客户端,安抚,纠正用户操作");
        return Result.error(e.getMessage());
    }


}
